#!/bin/bash

# For all script types, returning an exit code of 0 (success) means the
# script execution completed successfully.
#
# Requirements scripts can have the following exit codes that
# influence how the Client will handle the Fileset:
#
# - 210: This exit code will cause the Fileset to be treated like the
#        installation was successful (unless another requirements script fails,)
#        but the Fileset will not be downloaded nor installed.
#
# - 220: This exit code will prevent the installation and cause the client to
#        stop retrying unless a manual action is made (verify, reinstall, etc.)
#        or the Fileset is updated.
#
# Returning any other exit code but 0 (e.g. 1 or -1) will be reported as a
# "Requirements Failure: Script" in the Client Info window and Fileset Report.
# This will also prevent the contents of the Fileset from downloading and
# installing. In this case, requirements scripts will be executed every 2
# minutes and the Fileset will be installed when they all return 0.
#
# For other types of scripts, any non-zero exit code (e.g. 1 or -1) will cause the
# Fileset installation to fail and a script failure to be reported.
#
# If the script finishes without returning an exit code, the exit code 0
# (success) is assumed by default.
#
# Add the contents of your script below:

# Sanity check
if [ -e /Library/LaunchDaemons/com.filewave.block_applications.plist ]
then
	# Should always be true
	launchctl  print system/com.filewave.block_applications &> /dev/null
	if [ $? -eq 0 ]
	then
		launchctl unload -w /Library/LaunchDaemons/com.filewave.block_applications.plist
		rm /usr/local/etc/block_applications.sh
	fi
fi

exit 0